package com.baizhi.entity;

import com.baizhi.common.InsertGroup;
import com.baizhi.common.Phone;
import com.baizhi.common.UpdateGroup;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Null;

/**
 * <p>
 * 
 * </p>
 *
 * @author ljh
 * @since 2020-08-18
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class CmfzAdmin implements Serializable , UserDetails {

    private static final long serialVersionUID = 1L;

    @Null(message = "新增不能携带id",groups = {InsertGroup.class})
    @NotEmpty(message = "修改必须携带id",groups = {UpdateGroup.class})
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @Email
    private String username;

    //@NotEmpty
    @Phone(groups = {InsertGroup.class,UpdateGroup.class})
    private String password;


    //封装角色信息和权限信息
    /*@TableField(exist = false)
    private List<GrantedAuthority> authorities;*/

    /**
     * 获取授权信息
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        //return authorities;
        return null;
    }

    /**
     * 账户失效
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /**
     * 账户锁定
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 密码失效
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 账户可用
     * @return
     */
    @Override
    public boolean isEnabled() {
        return true;
    }
}
